package com.molichuxing.services.infrastructure.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.molichuxing.services.infrastructure.bean.RiskEmailBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.RiskEmailMapper;
import com.molichuxing.services.infrastructure.dto.request.modify.RiskEmailModifyDto;
import com.molichuxing.services.infrastructure.dto.response.RiskEmailDto;
import com.molichuxing.services.infrastructure.service.RiskEmailService;

@Service("riskEmailService")
public class RiskEmailServiceImpl implements RiskEmailService{

	@Autowired
	private RiskEmailMapper riskEmailMapper;
	
	/**
	 * 根据类型 和 接收类型 查询数据
	 * @param type
	 * @param receiveType
	 * @return
	 */
	@Override
	public List<RiskEmailDto> getByType(Integer type, Integer receiveType) {
		List<RiskEmailBean> list= riskEmailMapper.getByType(type, receiveType);
		List<RiskEmailDto> dtoList = Convert.toRiskEmailDtoList(list);
		return dtoList;
	}
	
	@Override
	public Boolean modify(List<RiskEmailModifyDto> list) {
		if(null == list || list.isEmpty()) {
			return true;
		}
		RiskEmailModifyDto riskEmailDto = list.get(0);
		Integer type = riskEmailDto.getType();
		Integer receiveType = riskEmailDto.getReceiveType();
		riskEmailMapper.delete(type,receiveType);
		for (RiskEmailModifyDto dto : list) {
			RiskEmailBean bean = new RiskEmailBean();
			BeanUtils.copyProperties(dto, bean);
			riskEmailMapper.create(bean);
		}
		return true;
	}
}
